package com.xfhy.share;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.xfhy.componentbase.ServiceFactory;

@Route(path = "/share/share")
public class ShareActivity extends AppCompatActivity {

    private static final String TAG = "ShareActivity";
    private Button mBtnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);

        initIntentData();

        mBtnLogin = findViewById(R.id.btn_login);
        mBtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareLogin();
            }
        });

        share();
    }

    private void initIntentData() {
        if (getIntent() != null) {
            String content = getIntent().getStringExtra("share_content");
            if (!TextUtils.isEmpty(content)) {
                ((TextView) findViewById(R.id.share_content)).setText(content);
            }
        }
    }

    private void shareLogin() {
        ARouter.getInstance().build("/account/login").navigation();
    }

    private void share() {
        if (ServiceFactory.getInstance().getAccountService().isLogin()) {
            Log.w(TAG, "share: 已登录");
            Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show();
        } else {
            Log.w(TAG, "share: 分析失败,用户未登录");
            Toast.makeText(this, "分享失败：用户未登录", Toast.LENGTH_SHORT).show();
            mBtnLogin.setVisibility(View.VISIBLE);
        }
    }
}
